package com.hp.attendance.dao;

import com.hp.attendance.entity.Overtime;
import com.hp.attendance.util.BaseDAO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class overtimeDao extends BaseDAO {

    public List<Overtime> getListOver() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        String sql="select * from overtime";
        List<Overtime> list = queryList(sql, new Object[0], new Overtime());
        return list;
    }

    public long getTotal() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        String sql="select count(1) from overtime";
        int i = queryCount(sql, new Object[0]);
        return i;
    }

    public List<Overtime> getListOverLimit(int pageNo , int pageSize) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        String sql="select * from overtime limit ?,?";
        Object[] obj={(pageNo-1)*pageSize,pageSize};
        List<Overtime> limitList = queryList(sql, obj, new Overtime());
        return limitList;

    }

    public void addOvertime(Overtime overtime) throws SQLException, IOException, ClassNotFoundException {
        String sql="insert into overtime values(null,?,?,?,null,null,null)";
        Object[] obj={overtime.getDepartment_number(),overtime.getEmployee_number(),overtime.getDay()};
        addOrUpdOrDel(sql,obj);
    }

    public Overtime queryOvertime(int id) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        String sql="select * from overtime where id=?";
        Object[] obj={id};
        Overtime overtime = queryOne(sql, obj, new Overtime());
        return overtime;
    }

    public void updateOvertime(Overtime overtime) throws SQLException, IOException, ClassNotFoundException {
        String sql="update overtime set department_number=?,employee_number=?,day=? where id=?";
        Object[] obj={overtime.getDepartment_number(),overtime.getEmployee_number(),overtime.getDay(),overtime.getId()};
        addOrUpdOrDel(sql,obj);
    }

    public void delOvertime(int id) throws SQLException, IOException, ClassNotFoundException {
        String sql="delete from overtime where id=?";
        Object[] obj={id};
        addOrUpdOrDel(sql,obj);
    }

}
